package st.lib.base.log;

import org.aspectj.lang.ProceedingJoinPoint;

import java.util.ArrayList;

import st.lib.base.ConfigType;
import st.lib.base.Shadow;

/**
 * @author zhangyu
 * @date 2018/9/20
 * 日志管理器
 */

public class LogManager implements IBehaviorAction {
    private ArrayList<IBehaviorAction> mActions;

    private LogManager() {
        try {
            mActions = Shadow.
                    getConfiguration(ConfigType.METHOD_BEHAVIOR);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void doWithPointBefore(ProceedingJoinPoint joinPoint) {
        if (mActions != null) {
            for (IBehaviorAction action : mActions) {
                action.doWithPointBefore(joinPoint);
            }
        }
    }

    @Override
    public void doWithPointAfter(ProceedingJoinPoint joinPoint) {
        if (mActions != null) {
            for (IBehaviorAction action : mActions) {
                action.doWithPointAfter(joinPoint);
            }
        }
    }

    private static final class Holder {
        private static final LogManager INSTANCE = new LogManager();
    }

    public static LogManager getInstance() {
        return Holder.INSTANCE;
    }
}
